package com.bawei.company

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.mvvm.BaseActivity
import com.bawei.company.databinding.ActivityCompanyBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/company/CompanyActivity")
class CompanyActivity : BaseActivity<ActivityCompanyBinding,CompanyViewModel>() {
    lateinit var compantAdapter: CompantAdapter
    override fun initView() {
        viewModel.compant()
        compantAdapter= CompantAdapter()
       binding.companyRec.adapter=compantAdapter
        binding.companyRec.layoutManager=LinearLayoutManager(this)
        compantAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/company/DetailActivity").withInt("id", compantAdapter.data[position].id).navigation()
        }

    }

    override fun initData() {
        viewModel.companySuccess.observe(this){
            compantAdapter.data.clear()
            compantAdapter.data.addAll(it)
            compantAdapter.notifyDataSetChanged()
        }
    }
}